package com.lysj.bhp.financial.repository;

import com.lysj.bhp.financial.domain.UserFinancialRecord;
import com.lysj.bhp.financial.vo.UserFinancialRecordVo;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.Date;
import java.util.List;

public interface UserFinancialRecordRepository extends JpaRepository<UserFinancialRecord, Long>, JpaSpecificationExecutor {



    @Query("SELECT new com.lysj.bhp.financial.vo.UserFinancialRecordVo(a.financialId,a.name,a.englishName,a.investmentDeadline,b.divide,a.earningsType,a.annualEarnings,a.interestDate,a.endIntersetDate,a.status,b.investmentPortion,a.investmentType,a.deadline) from Financial a,UserFinancialRecord b where a.financialId = b.financialId  AND a.earningsType = ?1 AND a.interestDate >= ?2 AND a.interestDate <= ?3 AND b.userId = ?4 ORDER BY a.interestDate desc ")
    Page<UserFinancialRecordVo> findUserFinancialRecord(Pageable page, Integer earningsType, Date begin_interestDate, Date end_interestDate, Long userId);


    List<UserFinancialRecord> findByFinancialId(Long financialId);

    List<UserFinancialRecord> findByFinancialIdAndIsRelease(Long financialId, Integer isRelease);;


}
